package funtastic.spellingbee;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PracticeAdapter extends ArrayAdapter<SpellingDetails>
{

    private Context               mContext;
    private List<SpellingDetails> mSpellingDetails;
    private int                   mTextViewResourceId;

    public PracticeAdapter(Context context, int textViewResourceId, List<SpellingDetails> spellingDetails)
    {
        super(context, textViewResourceId, spellingDetails);

        mContext = context;
        mTextViewResourceId = textViewResourceId;
        mSpellingDetails = spellingDetails;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        View rowView = convertView;

        if (rowView == null)
        {
            LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
            rowView = inflater.inflate(mTextViewResourceId, parent, false);
        }

        int currentPosition = (rowView.getTag() == null) ? -1 : ((Integer) rowView.getTag()).intValue();
        if (currentPosition != position)
        {
            TextView textViewSpelling = (TextView) rowView.findViewById(R.id.textViewSpelling);
            textViewSpelling.setText(mSpellingDetails.get(position).getSpelling());
        }

        return rowView;
    }
}
